exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.Service {
    constructor() {
        super();
        this.cms_area_model = this.db['cms_area'];
        this.device_catalog_video_model = this.db['device_catalog_video'];
    }
    /**
     * 查询行政区域
     */
    getAreaData(id) {
        var _this = this;

        return _asyncToGenerator(function* () {
            const orgId = `${id}`;
            try {
                return yield new _this.TreeService().findGrandchildrensAndSelf('cms_area', orgId);
            } catch (error) {
                return _this.exceptionService.handleError(error);
            }
        })();
    }
    /**
     * 分页获取设备列表
     */
    getDevice(data) {
        var _this2 = this;

        return _asyncToGenerator(function* () {
            const Op = _this2.db.Sequelize.Op;
            data.start = (parseInt(data.page) - 1) * parseInt(data.pageSize);
            const where = {};
            if (data.name) {
                where.name = {
                    [Op.like]: '%' + data.name + '%'
                };
            }
            try {
                return yield _this2.device_catalog_video_model.findAndCountAll({
                    where: where,
                    limit: parseInt(data.pageSize),
                    offset: parseInt(data.start)
                });
            } catch (error) {
                return _this2.exceptionService.handleError(error);
            }
        })();
    }
    /**
     * 获取设备列表
     */
    getAllDevice() {
        var _this3 = this;

        return _asyncToGenerator(function* () {
            try {
                return yield _this3.device_catalog_video_model.findAll();
            } catch (error) {
                return _this3.exceptionService.handleError(error);
            }
        })();
    }
    /**
     * 更改设备状态
     */
    changeDeviceEnable(data) {
        var _this4 = this;

        return _asyncToGenerator(function* () {
            try {
                const where = {
                    device_id: data.id
                };
                const parm = {
                    is_enable: data.is_enable
                };
                // if (data.is_enable == 1) {
                //     parm.is_enable = 0;
                // } else if (data.is_enable == 0) {
                //     parm.is_enable = 1;
                // }
                return yield _this4.device_catalog_video_model.update(parm, {
                    where
                });
            } catch (error) {
                return _this4.exceptionService.handleError(error);
            }
        })();
    }

    /**
     * 更改设备状态
     */
    changeDeviceInfo(data) {
        var _this5 = this;

        return _asyncToGenerator(function* () {
            try {
                const where = {
                    device_id: data.device_id
                };
                // if (data.is_enable == 1) {
                //     parm.is_enable = 0;
                // } else if (data.is_enable == 0) {
                //     parm.is_enable = 1;
                // }
                return yield _this5.device_catalog_video_model.update(data, {
                    where
                });
            } catch (error) {
                return _this5.exceptionService.handleError(error);
            }
        })();
    }

    deleteDevice(data) {
        var _this6 = this;

        return _asyncToGenerator(function* () {
            try {
                const where = {
                    device_id: data.device_id
                };
                // if (data.is_enable == 1) {
                //     parm.is_enable = 0;
                // } else if (data.is_enable == 0) {
                //     parm.is_enable = 1;
                // }
                return yield _this6.device_catalog_video_model.destory({
                    where
                });
            } catch (error) {
                return _this6.exceptionService.handleError(error);
            }
        })();
    }
};